package com.sudo.boot.service.sys.task;

import com.sudo.boot.base.exception.BizException;
import com.sudo.boot.grpc.annotation.TaskComponent;
import com.sudo.boot.grpc.annotation.TaskNote;
import lombok.extern.slf4j.Slf4j;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import java.util.Map;

@Slf4j
@TaskComponent
public class AdminTaskModule {


    /**
     * 建议：每天 凌晨 00:05:00 执行 (更新昨天的用户统计)
     */
    @TaskNote(desc = "用户统计-按天",params = "offset(Integer,true,2,日期偏移量)")
    public void stsUserBehaviorAndLoginByDay(Map<String,Object> paramMap) {
        int offset = Integer.parseInt(paramMap.get("offset").toString());

    }


    @TaskNote(desc = "用户过期检测")
    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
    public void updateAutoRoleStatus(){
        log.info("更新过期用户状态0条");
    }

    /**
     * 建议：
     *  # 每天早上 9:00 发送邮件
     *  # 每周一早上 9:00 发送邮件
     *  # 每月1号早上 9：00 发送邮件
     *
     */
    @TaskNote(desc = "用户行为数据邮件",
            params = {"from(Integer,true,-1,偏移量（小）)",
                    "to(Integer,true,-1,偏移量（大）)",
                    "unit(String,true,week,单位（day/week/month）)",
                    "email(String,true,xxx@qq.com...,邮箱（用‘逗号’分割）)"})
    public void emailAboutBehaviorAndLogin(Map<String,Object> paramMap) {
        int from = Integer.parseInt(paramMap.get("from").toString());
        int to = Integer.parseInt(paramMap.get("to").toString());
        String unit = paramMap.get("unit").toString();
        String email = paramMap.get("email").toString();
        if (from == 1) {
            throw new BizException("哈哈哈");
        }

    }

}
